package class07;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: https://www.lintcode.com/problem/66/description
 * @time: 2021/7/16 17:49
 * @author: lhy
 */
public class PreorderTraversal {

    public static List<Integer> f(TreeNode root, List<Integer> list){
        if(root == null){
            return null;
        }
        list.add(root.val);
        f(root.left,list);
        f(root.right,list);
        return list;
    }

    public List<Integer> preorderTraversal(TreeNode root) {
        // write your code here
        List<Integer> ans = new ArrayList<>();
        return f(root, ans);
    }
}
